#pragma once

#include <string>
#include <map>
#include <vector>
#include "Framework\Math\Vector.h"
#include "Framework\Util\ProgrammerArt.h"
#include "Quaternion.h"
#include "GL\gl.h"

#ifndef null
#define null 0l
#endif

void	 setf3(float* f3, float x,float y,float z);
void	 setf2(float* f2, float x,float y);

float	frand();
float	frrand(float min,float max);
bool	dequals(double a,double b,double tol);
bool	iszero(float a);
float	reciprocal_squareroot(float val);
float	reciprocal(float v);

vec3	randomSphericalPosition(float minrad,float radius);

bool	fileExists(const char *fileName);
bool	fileExistsAndIsNewerThan(const char* checkFile,const char* compareFile);

std::string format(const char *fmt, ...);

typedef struct{
	vec3	o;
	vec3	d;
	float mint;
	float maxt;
}Ray;

typedef struct{
	float u;
	float v;
}UV;


static void gluMakeIdentityf(GLfloat m[16]);
static int gluInvertMatrixf(const GLfloat src[16], GLfloat inverse[16]);

static void gluMultMatricesf(const GLfloat a[16], const GLfloat b[16],
				GLfloat r[16]);
static void gluMultMatrixVecf(const GLfloat matrix[16], const GLfloat in[4],
		      GLfloat out[4]);

GLint
gluUnProject(GLfloat winx, GLfloat winy, GLfloat winz,
		const GLfloat modelMatrix[16], 
		const GLfloat projMatrix[16],
        const GLint viewport[4],
	        GLfloat *objx, GLfloat *objy, GLfloat *objz);
bool IntersectTriangle(Ray& ray, vec3& p1, vec3& p2, vec3& p3, float* t, UV* uv);

bool	loadPNGInfo(const char*	fileName,std::string&	txt,int* pwidth=null,int* pheight=null,int* pchannels=null,char** pdata=null);
int		copyfile(const char* from,const char* to);
bool	listFiles(std::string path, std::string mask, std::vector<std::string>& files);
void	flushLog();
void	logging(bool	enable=true);

void	logstr(std::string& str,bool flush=false);
void	logstr(const char* str,bool flush=false);
std::string format_arg_list(const char *fmt, va_list args);
std::string format(const char *fmt, ...);


class color4 : public vec4
{
public:
	static color4 white;
	static color4 black;
	static color4 red;
	static color4 green;
	static color4 blue;
	color4(float r,float g,float b,float a){x=r;y=g;z=b;w=a;};
	color4(){*this=color4::white;};
	~color4(){};
};

